import { View, Text,Image } from '@tarojs/components'
import { AtIcon } from 'taro-ui'
import Taro from '@tarojs/taro'
import './address.less'
import HTTP from '../../service/api'
import { useState,useEffect } from 'react'
import store from '../../store'
const Address=()=>{
    const [dzInfo,setAddinfo]=useState([])
    useEffect(()=>{
        Taro.request({
            url:HTTP.api2+'/userAddress/findUserAddress',
            method:'post',
             header:{
                 'content-type':'application/x-www-form-urlencoded'
             },
             data:{
                 uid:'1'
                //  uid:JSON.parse(JSON.stringify(store.userInformation.id))
             },
             success:function(res) {
                setAddinfo(res.data.addresses)
                console.log(uid);
                // console.log(dzInfo);
             }
         })
    },[])
    //修改地址
    const xiugai=(item)=>{
        Taro.setStorageSync('infodata',JSON.stringify(item))
        Taro.navigateTo({
            url:'/pages/addAddress/addAddress?name=修改地址'
        })
    }
    //添加地址
    const add=()=>{
        // Taro.removeStorage({key:'address'})
        // Taro.removeStorage({key:'infodata'})
        Taro.navigateTo({
            url:'/pages/address/newaddress/newaddress?name=添加地址'
        })
        console.log(dzInfo);
    }
    return(
        <View>
            <View style={{fontSize:'30px',width:'90%',marginLeft:'5%',fontWeight:'bold'}}>我的地址</View>
            {dzInfo.map((item,index)=>
                <View style={{width:'90%',marginLeft:'5%',background:'white',boxShadow:'0px 0px 10px #DDDDDD'}} onClick={()=>(xiugai(item))}>
                    <View className='addList'>
                        <AtIcon value='map-pin' size='30' ></AtIcon>
                                <View className='addInfo'>
                                <View style={{fontSize:'14px',display:'flex',justifyContent:'space-between',alignItems:'center',fontWeight:'bold'}}>
                                    <Text >{item.username}</Text>
                                    <Text >{item.phone}</Text>
                                </View>
                                <View style={{fontSize:'14px',marginTop:'10px'}}>{item.shippingAddress}</View>
                                </View>
                            
                                {/* 下载的字体css要改class名，不然不能引用 */}
                                {/* <AtIcon prefixClass='iconfont' value='yonghu' size='30' color='#000'></AtIcon>
                                <AtIcon prefixClass='iconfont' value='dianshiji' size='30' color='#000'></AtIcon> */}
                            
                        <AtIcon value='settings' size='30' ></AtIcon>
                        <view className='tagInfo' style={item.defaultAddress?{display:'block'}:{display:'none'}}>默认</view>
                    </View>
                </View>
              )}
            <view className='addDZ' onClick={add}>添加地址</view>
        </View>
    )
}
export default Address;
